package net.diaowen.dwsurvey.service.impl;

import java.util.List;

import net.diaowen.common.plugs.page.Page;
import net.diaowen.dwsurvey.dao.AnChenFbkDao;
import net.diaowen.dwsurvey.entity.AnChenFbk;
import net.diaowen.dwsurvey.entity.Question;
import net.diaowen.dwsurvey.service.AnChenFbkManager;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.diaowen.common.service.BaseServiceImpl;

/**
 * 矩陈填空题
 * @author keyuan(keyuan258@gmail.com)
 *
 * https://github.com/wkeyuan/DWSurvey
 * http://dwsurvey.net
 */
@Service
public class AnChenFbkManagerImpl extends BaseServiceImpl<AnChenFbk, String> implements AnChenFbkManager {
	
	@Autowired
	private AnChenFbkDao anChenFbkDao;
	
	@Override
	public void setBaseDao() {
		this.baseDao=anChenFbkDao;
	}
	
	@Override
	public List<AnChenFbk> findAnswer(String belongAnswerId, String quId) {//belongAnswerId quId
		Criterion criterion1=Restrictions.eq("belongAnswerId", belongAnswerId);
		Criterion criterion2=Restrictions.eq("quId", quId);
		return anChenFbkDao.find(criterion1,criterion2);
	}

	@Override
	public Page<AnChenFbk> findAnswerByItem(Page<AnChenFbk> page,String quId, String rowId, String colId) {//quId,rowId,colId
		Criterion criterion1=Restrictions.eq("quRowId", rowId);
		Criterion criterion2=Restrictions.eq("quColId", colId);
		Criterion criterion3=Restrictions.eq("quId", quId);
//		quId=402880e564b309930164b55574aa0000&rowId402880e564b309930164b55574b90001&colId=402880e564b309930164b55574b90003
		return anChenFbkDao.findPage(page,criterion1,criterion2,criterion3);
	}


	@Override
	public void findGroupStats(Question question) {
		anChenFbkDao.findGroupStats(question);
	}

	@Override
	public void findGroupStatsTerm(Question question, String sex, String major) {
		anChenFbkDao.findGroupStatsTerm(question,sex,major);
	}
}
